package de.sky.mathparser.parser.lexer;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import de.sky.mathparser.parser.token.Token;

public class Lexer {

	public Lexer() {
	}

	public List<Token> lex(String line) throws ParseException {
		List<Token> tokens = new ArrayList<>(line.length());

		String[] chars = { "(", ")", "+", "-", "*", "/", "%" };
		for (String s : chars) {
			line = line.replace(s, " " + s + " ");
		}

		Scanner sc = new Scanner(line.trim());

		while (sc.hasNext()) {
			String t = sc.next();
			tokens.add(new Token(t));
		}

		sc.close();

		return tokens;
	}
}
